package cn.ljy.quicksnip.utils.file;


import cn.ljy.authority.config.upload.FileUploadConfig;
import cn.ljy.authority.model.common.AuthorityConstant;
import cn.ljy.common.utils.file.MyFileModel;
import cn.ljy.common.utils.file.MyFileUpload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

@Component
public class UemFileUploadUtil {
	@Autowired
	private FileUploadConfig fileUploadConfig;

	/**
	 *  上传图片资源，必须满足图片格式才能上传
	 * @param file 上传的文件
	 * @return 上传成功后的相对路径网址，例如:upload/2022/08/adf.jpg
	 */
	public MyFileModel uploadResourceOfPicture(MultipartFile file) {
		//上传图片资源，并将资源上传后的网址返回
		MyFileModel myFileModel= MyFileUpload.uploadMultipartFile(file,"image",fileUploadConfig.getResourceUploadSavePath(),fileUploadConfig.getResourceUploadUrl(),true, AuthorityConstant.ALLOW_UPLOAD_USER_PHOTO_SIZE);
		return myFileModel;
	}

	/**
	 *  上传资源，必须满足网站所有格式才能上传
	 * @param file 上传的文件
	 * @return 上传成功后的相对路径网址，例如:upload/2022/08/adf.jpg
	 */
	public MyFileModel uploadResource(MultipartFile file) {
		//上传资源，并将资源上传后的网址返回
		MyFileModel myFileModel= MyFileUpload.uploadMultipartFile(file,null,fileUploadConfig.getResourceUploadSavePath(),fileUploadConfig.getResourceUploadUrl(),true,AuthorityConstant.ALLOW_UPLOAD_RESOURCE_SIZE);
		return myFileModel;
	}
}
